// app.js
var http = require("./utils/request.js")
var url = require('./utils/interface.js')
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    wx.getStorage({
      key: 'token',
      success: res => {
        if(res.data != null && res.data != 0){
          // this.setData({
          //   userInfo: res.data,
          //   hasUserInfo: true,
          //   canIUseGetUserProfile:false,
          //   wx_login: false
          // })
        }else {
          wx.navigateTo({
            url: './pages/login/index'
          })
        }
      }
    })

  },

  /**
   * 用户后台登录:todo
   */
  appletUserLogin(code,iv,encryptedData){
    wx.setStorageSync("token", code)
    wx.switchTab({
      url: '../index/index'
    })
    return

    http.getRequest('form',url.URL_LOGIN, {
      code:code,
      encryptedData:encryptedData,
      iv:iv
    }, function(data){
      if(data.code != 0){
        wx.showToast({
          title: data.msg,
          icon: 'error',
          duration: 2000
         })
        return ;
      }
      // 存储用户token
      wx.setStorageSync("token", data.token)
      wx.switchTab({
        url: '../index/index'
      })
    }, function(){})
  },

  globalData: {
    userInfo: null
  }
})
